package com.cleaningcloud.cld.service.impl;

import com.cleaningcloud.cld.domain.dto.MaterialStatisticsDto;
import com.cleaningcloud.cld.domain.excelExport.StockStatisticsExport;
import com.cleaningcloud.cld.mapper.other.MaterialStatisticsMapper;
import com.cleaningcloud.cld.service.IMaterialStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class MaterialStatisticsServiceImpl implements IMaterialStatisticsService {

    @Autowired
    private MaterialStatisticsMapper materialStatisticsMapper;


    @Override
    public Map<String, Object> materialHeadStatistics() {
        Map<String, Object> resultMap = materialStatisticsMapper.stockHeadStatistics();
        if(resultMap == null){
            resultMap = new HashMap<>();
        }
        Map<String,Object> consumeMap = materialStatisticsMapper.consumeHeadStatistics();
        if(consumeMap  == null){
            consumeMap = new HashMap<>();
        }
        resultMap.putAll(consumeMap);
        Map<String,Object> transferMap = materialStatisticsMapper.transferHeadStatistics();
        if(transferMap == null){
            transferMap = new HashMap<>();
        }
        resultMap.putAll(transferMap);
        return resultMap;
    }

    @Override
    public List<Map<String, Object>> projectStatistics(MaterialStatisticsDto materialStatisticsDto) {
        return materialStatisticsMapper.projectStatistics(materialStatisticsDto);
    }

    @Override
    public List<Map<String, Object>> projectDetailsList(MaterialStatisticsDto materialStatisticsDto) {
        return materialStatisticsMapper.projectDetailsList(materialStatisticsDto);
    }

    @Override
    public List<Map<String, Object>> commodityTypeStatistics(MaterialStatisticsDto materialStatisticsDto) {
        materialStatisticsDto.getParams().put("groupType", "commodityType");
        return materialStatisticsMapper.commodityTypeStatistics(materialStatisticsDto);
    }

    @Override
    public List<Map<String, Object>> commodityTypeDetailsList(MaterialStatisticsDto materialStatisticsDto) {
        materialStatisticsDto.getParams().put("groupType", "commodityId");
        return materialStatisticsMapper.commodityTypeStatistics(materialStatisticsDto);
    }

    @Override
    public List<Map<String, Object>> commodityStatistics(MaterialStatisticsDto materialStatisticsDto) {
        return materialStatisticsMapper.commodityStatistics(materialStatisticsDto);
    }

    @Override
    public List<Map<String, Object>> transferDetails(MaterialStatisticsDto materialStatisticsDto) {
        return materialStatisticsMapper.transferDetails(materialStatisticsDto);
    }

    /**
     * @Author Shaw
     * @Description 备货统计
     * @date: 2025-03-19 15:51
     * @param: //TODO
     */
    @Override
    public List<Map<String, Object>> stockAppDetails(MaterialStatisticsDto materialStatisticsDto) {
        return materialStatisticsMapper.stockAppDetails(materialStatisticsDto);
    }

    /**
     * @Author Shaw
     * @Description 备货统计导出
     * @date: 2025-03-19 15:51
     * @param: //TODO
     */
    @Override
    public List<StockStatisticsExport> exportStockAppDetails(StockStatisticsExport stockStatisticsExport) {
        return materialStatisticsMapper.exportStockAppDetails(stockStatisticsExport);
    }
}